
<!--修改主表订单-->
<!--修改弹出框-->
<div class="wizard" id="wizard-pa">
    <form method="post" id="editForm">
        <h1>修改订单执行</h1>
        <div class="wizard-card" data-onValidated="setServerName" data-cardname="name">
            <h3><span>订单执行信息</span></h3>
            <input type="hidden" name="oid_exec_pa">

            <div class="wizard-input-section">
                <div class="form-group">
                    <label>订单评审号</label>
                    <select class="form-control" name="oid_pa" id="oid_pa" onchange="getOidEdit(this.options[this.options.selectedIndex].value)" data-validate="checkNull">
                        <option value=""></option>
                        {volist name="orders" id="v"}
                        <option value="{$v.oid}">{$v.oid}</option>
                        {/volist}
                    </select>
                </div>
                <div id="oidedit">
                    <div class="form-group">
                        <label>国家</label>
                        <input type="text" class="form-control" readonly name="sid_pa" id="sid_pa" data-validate=""/>
                    </div>
                    <div class="form-group">
                        <label>客户</label>
                        <input type="text" class="form-control" readonly name="cid_pa" id="cid_pa" data-validate=""/>
                    </div>
                    <div class="form-group">
                        <label>下单联系人</label>
                        <input type="text" class="form-control" readonly name="order_placer_pa" data-validate=""/>
                    </div>
                    <div class="form-group">
                        <label>生产状态</label>
                        <input type="text" class="form-control" readonly name="is_status_oid_pa" id="is_status_oid_pa" data-validate=""/>
                    </div>
                </div>

            </div>

        </div>

        <div class="wizard-card" data-cardname="group">
            <h3><span>模块信息</span></h3>

            <div class="wizard-input-section">
                <div class="form-group">
                    <label>电子模块类型</label>
                    <select class="form-control" name="model_id_pa" id="model_id_pa" data-validate="">
                        {volist name="modelTypes" id="v"}
                        <option value="{$v['model_id']}">{$v.model_type}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group">
                    <label>模块订单号</label>
                    <input type="text" class="form-control" name="model_num_pa" id="model_num_pa" data-validate="" onchange="getModelNumEdit()"/>
                </div>
                <div class="form-group">
                    <label>模块数量</label>
                    <div>
                        <input type="text" name="model_qty_pa" id="model_qty_pa" data-validate="" style="width: 46%;height: 34px;float: left;margin-bottom: 14px;"/>
                        <input type="text" readonly id="surplus_edit" style="color:red;border: 0;width: 53%;height: 34px;float: left;margin-left: 1%;margin-bottom: 14px;"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="model_start_pa">模块下单开始-结束时间</label>
                    <div class="form-group">
                        <span class="input-group-addon new-date-i"><i class="fa fa-calendar"></i></span>
                        <input type="date" id="model_start_pa" name="model_start_pa" class="new-date">
                        <input type="text" placeholder="--" class="new-input">
                        <input type="date" id="model_end_pa" name="model_end_pa" class="new-date">
                    </div>

                </div>
            </div>
        </div>

        <div class="wizard-card" data-onload="" data-cardname="location">
            <h3><span>基表信息</span></h3>

            <div class="wizard-input-section" id="meter_editpa">
                <div class="form-group">
                    <label>基表订单号</label>
                    <input type="text" name="order_num_pa" class="form-control">
                </div>
                <div class="form-group">
                    <label>开始表号-结束表号</label>
                    <div class="form-group">
                        <input type="text" name="meter_start_pa" class="new-form-control">
                        <input type="text" placeholder="--" class="new-input">
                        <input type="text" name="meter_end_pa" class="new-form-control">
                    </div>
                </div>
                <div class="form-group forhid" id="meter_num_fixed">
                    <input type="text" name="meter_len_pa" readonly style="border: 0;color: red;width: 100%;">
                </div>
                <div class="form-group">
                    <label>基表组装开始-完成时间</label>
                    <div class="form-group">
                        <span class="input-group-paon new-date-i"><i class="fa fa-calendar"></i></span>
                        <input type="date" id="assem_start_pa" name="assem_start_pa" class="new-date">
                        <input type="text" placeholder="--" class="new-input">
                        <input type="date" id="assem_end_pa" name="assem_end_pa" class="new-date">
                    </div>
                </div>

            </div>
        </div>

        <div class="wizard-card">
            <h3><span>生产信息</span></h3>

            <div class="wizard-input-section">
                <div class="form-group">
                    <label>制造商</label>
                    <select class="form-control" name="mf_id_pa" id="mf_id_pa" data-validate="">
                        {volist name='manus' id='v'}
                        <option value="{$v['mf_id']}">{$v.manufacturer}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group">
                    <label>生产负责人</label>
                    <select class="form-control" name="pid_pa" id="pid_pa" data-validate="">
                        {volist name='principles' id='v'}
                        <option value="{$v['pid']}">{$v.product_principle}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group">
                    <label>客户化工具</label>
                    <select class="form-control" name="custom_tool_pa" id="custom_tool_pa">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>

                <div class="form-group">
                    <label>生产数据校验</label>
                    <select class="form-control" name="data_verify_pa" id="data_verify_pa" data-validate="">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>发货状态</label>
                    <select class="form-control" name="is_status_pa" id="is_status_pa" data-validate="">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>

            </div>
        </div>


        <div class="wizard-card">
            <h3><span>其他相关信息</span></h3>

            <div class="wizard-input-section">

                <div class="form-group">
                    <label>备注</label>
                    <input type="text" name="comments_pa" class="form-control" data-validate="">
                </div>

            </div>
        </div>
    </form>
</div>
<!--修改弹出框-->
<script src="__JS__/jquery.js"></script>
<script type="text/javascript">
    //根据订单评审id展示相关信息
    function getOidEdit(oid) {
        //$('#oidedit').removeClass('forhid')
        if(!oid){
            $('#oidedit').addClass('forhid')
        }else{
            $('#oidedit').removeClass('forhid')
        }
        $.post("{:url('Order/one')}",{oid:oid},function(data){
            // console.log(data);
            if(data) {
                $("input[name='cid_pa']").val(data[0].client);
                $("input[name='sid_pa']").val(data[0].state);
                $("input[name='is_status_oid_pa']").val(data[0].status);
                $("input[name='order_placer_pa']").val(data[0].order_placer);
                var meterLen = data[0].meter_len;
                //如果没有表号长度
                if(meterLen != 0){
                    $('#meter_num_fixed').removeClass('forhid')
                    $("input[name='meter_len_pa']").val('请输入 '+meterLen+' 位表号')
                }else{
                    $('#meter_num_fixed').removeClass('forhid')
                    $("input[name='meter_len_pa']").val('请输入 10,11,12或13 位表号')
                }
                var meterId = data[0].meter_id
                // console.log(meterId)
                if(meterId.length != 0){
                    $('#meter_editpa').removeClass('forhid')

                }else{
                    $('#meter_editpa').addClass('forhid')
                    //值为0
                    $("input[name='order_num_pa']").val('')
                    $("input[name='meter_start_pa']").val('')
                    $("input[name='meter_end_pa']").val('')
                    $("input[name='assem_start_pa']").val('')
                    $("input[name='assem_end_pa']").val('')
                }
            }
        },'json');
    }

    function edit(oid_exec) {
        //post前设为同步
        //$.ajaxSettings.async = false;
        $.post("{:url('Execorder/one')}",{oid_exec:oid_exec},function(data){
            // console.log(data);
            //主表订单
            if(data) {
                //显示当前的
                $('#oid_pa').append("<option value='"+data[0].oid+"'>"+data[0].oid+"</option>");

                $("input[name='oid_exec_pa']").val(data[0].oid_exec);
                /*订单评审信息*/
                $("select[name='oid_pa']").val(data[0].oid);
                getOidEdit(data[0].oid);
                /*模块信息*/
                $("input[name='model_qty_pa']").val(data[0].model_qty);
                $("select[name='model_id_pa']").val(data[0].model_id);
                $("input[name='model_num_pa']").val(data[0].model_num);
                $("input[name='model_start_pa']").val(data[0].model_start);
                $("input[name='model_end_pa']").val(data[0].model_end);
                //如果模块订单号为空
                if(!data[0].model_num){
                    $("#surplus_edit").val('')
                }else{
                    $("#surplus_edit").val('剩余模块:'+data[0].surplus+'(当前订单数量已减)')
                }

                /*基表信息*/
                $("input[name='order_num_pa']").val(data[0].order_num);
                $("input[name='meter_start_pa']").val(data[0].meter_start);
                $("input[name='meter_end_pa']").val(data[0].meter_end);
                $("input[name='assem_start_pa']").val(data[0].assem_start);
                $("input[name='assem_end_pa']").val(data[0].assem_end);

                /*生产信息*/
                $("select[name='mf_id_pa']").val(data[0].mf_id);
                $("select[name='pid_pa']").val(data[0].pid);
                $("select[name='custom_tool_pa']").val(data[0].custom_tool);
                $("select[name='data_verify_pa']").val(data[0].data_verify);
                $("select[name='is_status_pa']").val(data[0].is_status);

                /*其他相关信息*/
                $("select[name='sale_id_pa']").val(data[0].sale_id);
                /*$("input[name='sum_amounts_pa']").val(data[0].sum_amounts);
                $("select[name='sum_units_pa']").val(data[0].sum_units);*/
                $("input[name='comments_pa']").val(data[0].comments);
            }
        },'json');
        foreditpa.show()
        foreditpa.on("submit", function(wizard) {
            setTimeout(function() {
                wizard.trigger("success");
                wizard.hideButtons();
                wizard._submitting = false;
                wizard.showSubmitCard("success");
                wizard.updateProgressBar(0);
            }, 3000);
            esavepa();
            foreditpa.reset().close();
            //刷新页面
            window.location.reload();
        });

    }
    function esavepa() {
        var oid_exec = $("input[name='oid_exec_pa']").val();
        /*订单评审信息*/
        var oid = $("select[name='oid_pa']").val();

        /*模块信息*/
        var model_qty = $("input[name='model_qty_pa']").val();
        var model_id = $("select[name='model_id_pa']").val();
        var model_num = $("input[name='model_num_pa']").val();
        var model_start = $("input[name='model_start_pa']").val();
        var model_end = $("input[name='model_end_pa']").val();

        /*基表信息*/
        var order_num = $("input[name='order_num_pa']").val();
        var meter_start = $("input[name='meter_start_pa']").val();
        var meter_end = $("input[name='meter_end_pa']").val();
        var assem_start = $("input[name='assem_start_pa']").val();
        var assem_end = $("input[name='assem_end_pa']").val();

        /*生产信息*/
        var mf_id = $("select[name='mf_id_pa']").val();
        var pid = $("select[name='pid_pa']").val();
        var custom_tool = $("select[name='custom_tool_pa']").val();
        var data_verify = $("select[name='data_verify_pa']").val();
        var is_status = $("select[name='is_status_pa']").val();

        /*其他相关信息*/
        var sale_id = $("select[name='sale_id_pa']").val();
        /*var sum_amounts = $("input[name='sum_amounts_pa']").val();
        var sum_units = $("select[name='sum_units_pa']").val();*/
        var comments = $("input[name='comments_pa']").val();

        var data = {'oid_exec':oid_exec,'oid':oid,'model_qty':model_qty,'model_id':model_id,'model_num':model_num,'model_start':model_start,'model_end':model_end,
            'order_num':order_num,'meter_start':meter_start,'meter_end':meter_end,'assem_start':assem_start,'assem_end':assem_end,
            'mf_id':mf_id,'pid':pid,'custom_tool':custom_tool,'data_verify':data_verify,'is_status':is_status,
            'sale_id':sale_id,'comments':comments};
        //console.log(data)
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "{:url('Execorder/esave')}",//url
            data: data,
            success: function (result) {
                //console.log(result)
                var code = result.code
                var msg = result.msg
                var need = result.need
                //console.log(need)
                changeText(msg, code)
                //console.log('123'+code)

            },
            error:function (result) {
                var code = 0
                var msg = '服务器错误';
                changeText(msg, code)

            }
        });
    }

    function getModelNumEdit() {
        var modelNum = $('#model_num_pa').val();

        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "{:url('Execorder/getModelNum')}",//url
            data: {'model_num':modelNum},
            success: function (result) {
                var num = result.model_qty;
                var start = result.model_start;
                var end = result.model_end;
                var first = result.firstadd;
                //console.log(num+','+start+','+end)
                $('#model_qty_pa').val(num)
                $('#model_start_pa').val(start)
                $('#model_end_pa').val(end)
                //console.log('success'+result)

                if(first != ''){
                    $('#surplus_edit').val(first)
                    /*$('#firstadd_edit').removeClass('forhid')
                    $('#firstadd_edit').val(first)*/
                }


            },
            error:function (result) {
                //console.log('error'+result)
                alert('服务出错')
            }
        });
    }
</script>
